<template>
	<view class="mainpadding">
		<view class="xiahuaxian">
			<view class="ershiba fonweight xiaohei">请输入您现使用的密码</view>
			<input class="margin_top" type="number" placeholder="请输入您现在使用的密码" v-model="password">
		</view>
		<view class="xiahuaxian margin_top">
			<view class="ershiba fonweight xiaohei">请输入您想修改的密码</view>
			<input class="margin_top" type="number" placeholder="请输入您想修改的密码" v-model="newpassword">
		</view>
		<view class="margin_top xiaohong strongtext">！
			<text class="xiaohei strongtext">密码可输入除空格、汉字外任意字符（最少8位最多16位）</text>
		</view>
		<view class="gudingdb ffffff mainpadding">
			<view class="bighbtn" @click="submit">提交</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				password:"",
				newpassword:"",
			}
		},
		methods: {
			submit(){
				if(this.password==""){
					httpRequest.toast("请输入旧密码")
					return false
				}
				if(this.newpassword==""){
					httpRequest.toast("请输入新密码")
					return false
				}
				httpRequest.request('/api/user/changepwd', 'GET', {
					password:this.password,
					newpassword:this.newpassword
				}).then(res => {
					if(res.code==1){
						uni.removeStorageSync('token');
						uni.removeStorageSync('user_id');
						httpRequest.toast("修改密码成功，已自动为您退出登录")
						setTimeout(() => {
							uni.navigateBack({
								delta:2
							})
						}, 1000)
					}else{
						httpRequest.toast(res.msg)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>
